import { Component, OnInit } from '@angular/core';

declare var form: any;

@Component({
  templateUrl: './portal.document.component.html'
})
export class PortalDocumentComponent implements OnInit {

  fs: any = null;
  sideDic: any = null;
  columnDic: any = null;
  subjectDic: any = null;

  constructor() {
    this.fs = new form.FormSimpleService('cms_document', {
      orderObject: { publishDate: 1 },
      keyField: 'id',
      randomFields: ['id']
    });
    // 加载统计数据
    this.fs.statisticsCallback = (sdata) => {
      if (this.fs.statisname === null || this.fs.statisname === '') {
        this.fs.selectStatistics(sdata[0]);
      }
    };
    this.fs.statistics();

    this.sideDic = new form.DictionaryService('cms_site');
    this.sideDic.loadAll();

    this.columnDic = new form.DictionaryService('cms_column');
    this.columnDic.loadAll();

    this.subjectDic = new form.DictionaryService('cms_subject');
    this.subjectDic.loadAll();
  }

  ngOnInit(): void {
  }

  editRow(item) {
    if (item) {
      window.open('#protal_docinfo_mis?info=true&id=' + item.id);
    } else {
      window.open('#protal_docinfo_mis?info=true');
    }
  }

  // 重置
  reset() {
    this.fs.resetQueryObject();
    this.fs.loadData(true);
    this.fs.statistics();
    this.columnDic.filter((item) => {
      return true;
    });
    this.subjectDic.filter((item) => {
      return true;
    });
  }

  // 站点下拉选择后
  treeClick(e) {
    this.fs.queryObject.subject = 'nullItem';
    this.fs.queryObject.column = 'nullItem';
    this.columnDic.filter((item) => {
      if (item.other.siteId === e) {
        return true;
      } else {
        return false;
      }
    });
    this.subjectDic.filter((item) => {
      if (item.other.siteId === e) {
        return true;
      } else {
        return false;
      }
    });
  }
}
